#ifndef __GOFGAME_COMMON_H__
#define __GOFGAME_COMMON_H__

#include "gofgame/common/Ref.h"
#include "gofgame/common/resource/Resource.h"
#include "gofgame/common/cxx_0x.h"
#include "gofgame/common/IllegalStateException.h"

namespace gofgame {
	namespace common {
		namespace resource {
			template <typename T>
			struct TypedResource : public Resource {
			public:
				Ref<T> unwrap() const {
					if (!this->value) {
						_throw(IllegalStateException, "The resource is not loaded or it is loaded failed");
					}
					return this->value;
				}

			protected:
				virtual void onUnload() _override {
					this->value = nullptr;
				}

				Ref<T> value;
			};
		}
	}
}

#endif //__GOFGAME_COMMON_H__